/**
 * @param {number[]} nums
 * @return {number[][]}
 */
var threeSum = function(nums) {
    nums=nums.sort((a,b)=>a-b)
    const result =[];
    let sum = 0;
    for(let i=0;i<nums.length-2;i++){
        if(nums[i]===nums[i-1]){
            continue;
        }
        for(let k=i+1;k<nums.length-1;k++){
            for(let m = k+1;m<nums.length;m++){
                sum=nums[i]+nums[k]+nums[m]
                let target=[nums[i],nums[k],nums[m]]
                if(sum===0 && !result.find(arr=>arr.every((val, index) => val === target[index]))){
                    result.push(target)
                    break;
                }
            }
        }
    }

    return result
};